﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.RDLC

Partial Class Documentation
    Inherits System.Web.UI.Page

#Region " Properties "

    Public Property CurrentPage() As Integer
        Get
            'Looks for the current page in ViewState
            Dim objPage As Object = ViewState("_CurrentPage")
            If objPage Is Nothing Then
                Return 0
            Else
                'default to showing the first page
                Return CInt(objPage)
            End If
        End Get
        Set(ByVal value As Integer)
            ViewState("_CurrentPage") = value
        End Set
    End Property

    Public Property PageSize() As Integer
        Get
            'Looks for the current page in ViewState
            Dim objPageSize As Object = ViewState("_PageSize")
            If objPageSize Is Nothing Then
                Return 10
            Else
                'default to showing the first page
                Return CInt(objPageSize)
            End If
        End Get
        Set(ByVal value As Integer)
            ViewState("_PageSize") = value
        End Set
    End Property

#End Region

#Region " Paging and Page Size "

    Protected Sub lnkHead10Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead10Item.Click
        PageSize = 10
        LoadDoc()
    End Sub

    Protected Sub lnkHead25Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead25Item.Click
        PageSize = 25
        LoadDoc()
    End Sub

    Protected Sub lnkHead100Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead100Item.Click
        PageSize = 100
        LoadDoc()
    End Sub

    Protected Sub lnkHead150Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead150Item.Click
        PageSize = 150
        LoadDoc()
    End Sub

    Protected Sub lnkFoot10Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot10Item.Click
        PageSize = 10
        LoadDoc()
    End Sub

    Protected Sub lnkFoot25Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot25Item.Click
        PageSize = 25
        LoadDoc()
    End Sub

    Protected Sub lnkFoot100Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot100Item.Click
        PageSize = 100
        LoadDoc()
    End Sub

    Protected Sub lnkFoot150Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot150Item.Click
        PageSize = 150
        LoadDoc()
    End Sub

    Protected Sub btnMoveFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveFirst.Click
        CurrentPage = 0
        txtPageNo.Text = CurrentPage + 1
        LoadDoc()
    End Sub

    Protected Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If CurrentPage > 0 Then
            CurrentPage = CurrentPage - 1
            txtPageNo.Text = CurrentPage + 1
            LoadDoc()
        End If
    End Sub

    Protected Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGo.Click
        If CInt(txtPageNo.Text < 1) Then
            txtPageNo.Text = 1
        End If

        If CInt(txtPageNo.Text > CInt(lblMaxPageCount.Text)) Then
            txtPageNo.Text = CInt(lblMaxPageCount.Text) + 1
        End If

        CurrentPage = CInt(txtPageNo.Text) - 1
        LoadDoc()

    End Sub

    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If CurrentPage < CInt(lblMaxPageCount.Text) Then
            CurrentPage = CurrentPage + 1
            txtPageNo.Text = CurrentPage + 1
            LoadDoc()
        End If
    End Sub

    Protected Sub btnMoveLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveLast.Click
        CurrentPage = CInt(lblMaxPageCount.Text)
        txtPageNo.Text = CurrentPage + 1
        LoadDoc()
    End Sub

#End Region

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session.Item("StaffId") Is Nothing Then
            Response.Redirect("default.aspx")
        End If

        'Edited by minginn @ 27/6/2011 - to load the same search when user back from other page
        If Not Session("Back") Is Nothing Then
            Dim strBack As String = Session("Back").ToString
            Dim arr() As String = strBack.Split("ڡ")
            '0-Back Page
            '1-Page Size
            '2-Current Page
            '3-Type
            If arr(0).ToString.Contains("Documentation.aspx") Then
                PageSize = CInt(arr(1).ToString)
                CurrentPage = CInt(arr(2).ToString)
                ddlReportName.SelectedValue = arr(3).ToString
                Session.Remove("Back")
                LoadDoc()
            Else
                Session.Remove("Back")
            End If
        End If

        If Not Page.IsPostBack Then

            lblStaffUID.Text = Session.Item("StaffId").ToString
            lblStaffType.Text = Session.Item("StaffType").ToString
        End If
    End Sub

    Protected Sub btnCreate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreate.Click
        Session.Remove("id")
        Select Case ddlReportName.SelectedValue
            Case "1"
                Response.Redirect("DocRentTakeUp.aspx")
            Case "2"
                Response.Redirect("DocSaleTakeUp.aspx")
            Case "3"
                Response.Redirect("DocTakeUpAuction.aspx")
            Case "4"
                Response.Redirect("DocProposal.aspx")
            Case "5"
                Response.Redirect("DocExclusive.aspx")
        End Select
    End Sub

    Protected Sub btnRetrieve_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRetrieve.Click
        LoadDoc()
    End Sub

    Private Sub LoadDoc()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        Dim StaffFilter As String = String.Empty

        If lblStaffType.Text = "2" Then
            StaffFilter = " WHERE CreateBy = @CreateBy"
            objDB.AddParameter("CreateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        End If
        Select Case ddlReportName.SelectedValue
            Case "1"
                objDB.dbVariable.SQLString = "SELECT DocRentId as DocId, DocRentTitle + ' (' + DocOpenRefNo + ')' as Title, " & _
                                            "CreateDate FROM AW_DocTakeUpRent" & StaffFilter & lblHidSortType.Text
            Case "2"
                objDB.dbVariable.SQLString = "SELECT DocSaleId as DocId, DocSaleTitle + ' (' + DocOpenRefNo + ')' as Title, " & _
                                            "CreateDate FROM AW_DocTakeUpSale" & StaffFilter & lblHidSortType.Text
            Case "3"
                objDB.dbVariable.SQLString = "SELECT DocAucId as DocId, DocAucTitle as Title, " & _
                                            "CreateDate FROM AW_DocTakeUpAuction" & StaffFilter & lblHidSortType.Text
            Case "4"
                objDB.dbVariable.SQLString = "SELECT DocPropId as DocId, DocPropTitle as Title, " & _
                                            "CreateDate FROM AW_DocProposal" & StaffFilter & lblHidSortType.Text
            Case "5"
                objDB.dbVariable.SQLString = "SELECT DocExId as DocId, DocExTitle as Title, " & _
                                            "CreateDate FROM AW_DocExclusive" & StaffFilter & lblHidSortType.Text
        End Select

        
        objDB.FillData(TempDT, "AW_Documentation", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        'Creating a Paged Datasouce
        Dim objPaged As New PagedDataSource
        objPaged.DataSource = TempDT.DefaultView
        objPaged.AllowPaging = True
        objPaged.PageSize = PageSize
        objPaged.CurrentPageIndex = CurrentPage

        lblHeadNoOfItem.Text = TempDT.Rows.Count
        lblFootNoOfItem.Text = TempDT.Rows.Count

        repDocumentation.DataSource = objPaged
        repDocumentation.DataBind()

        lblMaxPageCount.Text = objPaged.PageCount - 1
        lblTotalPage.Text = " of " & objPaged.PageCount
    End Sub

    Private Function SortType(ByVal strSortType As String) As String
        Dim strSort As String
        If Right(strSortType, 1) = "▼" Then
            strSort = "ASC"
        Else
            strSort = "DESC"
        End If
        Return strSort
    End Function

    Protected Sub lnkDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkDate.Click
        If lnkDate.Text = "Date▼" Then
            lnkDate.Text = "Date▲"
        Else
            lnkDate.Text = "Date▼"
        End If

        lblHidSortType.Text = " ORDER BY CreateDate " & SortType(lnkDate.Text) & ", Title " & SortType(lnkTitle.Text)
        LoadDoc()
    End Sub

    Protected Sub lnkTitle_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkTitle.Click
        If lnkTitle.Text = "Title▼" Then
            lnkTitle.Text = "Title▲"
        Else
            lnkTitle.Text = "Title▼"
        End If

        lblHidSortType.Text = " ORDER BY Title " & SortType(lnkTitle.Text) & ", CreateDate " & SortType(lnkDate.Text)
        LoadDoc()
    End Sub

    Protected Sub repDocumentation_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repDocumentation.ItemCommand
        If e.CommandName = "EditItem" Then
            Dim strBack As String
            strBack = "Documentation.aspx" & "ڡ" & PageSize & "ڡ" & CurrentPage & "ڡ" & ddlReportName.SelectedValue
            Session.Add("Back", strBack)
            Dim DocId As String = CType(repDocumentation.Items(e.CommandArgument).FindControl("lblRepDocId"), Label).Text
            Session.Add("id", DocId)
            Select Case ddlReportName.SelectedValue
                Case "1"
                    Response.Redirect("DocRentTakeUp.aspx")
                Case "2"
                    Response.Redirect("DocSaleTakeUp.aspx")
                Case "3"
                    Response.Redirect("DocTakeUpAuction.aspx")
                Case "4"
                    Response.Redirect("DocProposal.aspx")
                Case "5"
                    Response.Redirect("DocExlusive.aspx")
            End Select
        ElseIf e.CommandName = "DownloadItem" Then
            Dim TempDT As New Data.DataTable
            Dim PropertyDT As New Data.DataTable
            Dim DocId As String = CType(repDocumentation.Items(e.CommandArgument).FindControl("lblRepDocId"), Label).Text
            Select Case ddlReportName.SelectedValue
                Case "1"
                    TempDT = LoadRent(DocId)
                Case "2"
                    TempDT = LoadSale(DocId)
                Case "3"
                    TempDT = LoadAuction(DocId)
                Case "4"
                    TempDT = LoadProposal(DocId)
                    PropertyDT = LoadProperty(DocId)
                Case "5"
                    TempDT = LoadExclusive(DocId)
            End Select

            Dim CurrentUser As String = GetName()
            Dim PrintStr As String = "Printed by " & CurrentUser & " on " & Format(Now(), "dd-MMM-yyyy")

            If TempDT IsNot Nothing Then
                Select Case ddlReportName.SelectedValue
                    Case "1"
                        Dim objRDLC As New RDLC("report/rptDocRentTakeUp.rdlc", "DocRentTakeUp")
                        TempDT.TableName = "dsDocRentTakeUp_AW_DocRentTakeUp"
                        objRDLC.AddDatabase(TempDT)
                        objRDLC.AddParameter("PrintStr", PrintStr)
                        objRDLC.ExportReport(RDLC.ExportTypeFormat.PDF, HttpContext.Current)
                    Case "2"
                        Dim objRDLC As New RDLC("report/rptDocSaleTakeUp.rdlc", "DocSaleTakeUp")
                        TempDT.TableName = "dsDocSaleTakeUp_AW_DocSaleTakeUp"
                        objRDLC.AddDatabase(TempDT)
                        objRDLC.AddParameter("PrintStr", PrintStr)
                        objRDLC.ExportReport(RDLC.ExportTypeFormat.PDF, HttpContext.Current)
                    Case "3"
                        Dim objRDLC As New RDLC("report/rptDocTakeUpAuction.rdlc", "DocTakeUpAuction")
                        TempDT.TableName = "dsDocTakeUpAuction_AW_DocTakeUpAuction"
                        objRDLC.AddDatabase(TempDT)
                        objRDLC.AddParameter("PrintStr", PrintStr)
                        objRDLC.ExportReport(RDLC.ExportTypeFormat.PDF, HttpContext.Current)
                    Case "4"
                        Dim objRDLC As New RDLC("report/rptDocProposal.rdlc", "DocProposal")
                        TempDT.TableName = "dsDocProposal_AW_DocProposal"
                        PropertyDT.TableName = "dsDocProposal_AW_DocProposalProperty"
                        objRDLC.AddDatabase(TempDT)
                        objRDLC.AddDatabase(PropertyDT)
                        objRDLC.AddParameter("PrintStr", PrintStr)
                        objRDLC.AddParameter("Category", TempDT.Rows(0).Item("ListType").ToString)
                        objRDLC.ExportReport(RDLC.ExportTypeFormat.PDF, HttpContext.Current)
                    Case "5"
                        Dim objRDLC As New RDLC("report/rptDocExclusive.rdlc", "DocExclusive")
                        TempDT.TableName = "dsDocExclusive_AW_DocExclusive"
                        objRDLC.AddDatabase(TempDT)
                        objRDLC.AddParameter("PrintStr", PrintStr)
                        objRDLC.ExportReport(RDLC.ExportTypeFormat.PDF, HttpContext.Current)
                End Select
            End If
        End If
    End Sub

    Private Function GetName() As String
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable
        Dim StaffName As String = String.Empty

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT Name FROM AW_Staff WHERE StaffId=@StaffId"
        objDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        objDB.FillData(TempDT, "AW_Staff", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        For Each dtrow As Data.DataRow In TempDT.Rows
            If dtrow.Item("Name").ToString <> "" Then
                StaffName = dtrow.Item("Name").ToString
            End If
        Next

        Return StaffName
    End Function

    Private Function LoadRent(ByVal DocId As String) As Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT d.DocRentTitle, d.DocOpenRefNo, d.TransactionId, d.Category, d.REN, d.Lister, d.DocDate, d.MonthlyRental, d.Premise, " & _
                                    "d.Duration, d.DurationType, d.AnotherDuration, d.AnotherType, d.UponAt, d.Increase, " & _
                                    "d.CommencementDate, d.PremisesUse, d.TerminationClause, d.RentFreePeriod, d.Requisition, " & _
                                    "d.LandlordName, d.LandlordNRIC, d.LandlordAddress, d.LandlordContactPerson, " & _
                                    "d.LandlordTel, d.LandlordFax, d.LandlordMobile, d.LandlordVMT, d.AgencyFee, d.GovTax, " & _
                                    "d.GovPercent, d.LandlordTA, d.LandlordStampingFee, d.BankAcc, d.TenantName, d.TenantNRIC, " & _
                                    "d.TenantAddress, d.TenantContactPerson, d.TenantTel, d.TenantFax, d.TenantMobile, " & _
                                    "d.TenantVMT, d.DepositMonth, d.Deposit, d.AdvanceMonth, d.Advance, d.WEDeposit, " & _
                                    "d.Disbursement, d.TenantTA, d.TenantStampingFee, d.ReferralFee, ISNULL(d.UpdateDate, d.CreateDate) as CreateDate, " & _
                                    "ISNULL(u.Name, c.Name) as CreateBy, d.StatusDelete FROM AW_DocTakeUpRent d " & _
                                    "LEFT JOIN AW_Staff u ON d.UpdateBy = u.StaffId LEFT JOIN AW_Staff c ON " & _
                                    "d.CreateBy = c.StaffId WHERE DocRentId=@DocRentId"
        objDB.AddParameter("DocRentId", Data.SqlDbType.UniqueIdentifier, New Guid(DocId))
        objDB.FillData(TempDT, "DocTakeUpRent", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()
        Return TempDT
    End Function

    Private Function LoadSale(ByVal DocId As String) As Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT d.DocSaleTitle, d.DocOpenRefNo, d.TransactionId, d.Category, d.REN, d.Lister, d.DocDate, d.TransactedPrice, d.Premise, " & _
                                    "d.BalMonthChar, d.BalMonthInt, d.ModeOfPayment, d.ExMonthChar, d.ExMonthInt, " & _
                                    "d.WInterest, d.Interest, d.SPADate, d.Remarks, d.VendorName, d.VendorNRIC, d.VendorAddress, " & _
                                    "d.VendorContactPerson, d.VendorTel, d.VendorFax, d.VendorMobile, d.VendorComission, " & _
                                    "d.VendorSCompany, d.VendorSAddress, d.VendorSContactPerson, d.VendorSTel, d.VendorSFax, " & _
                                    "d.VendorSMobile, d.PurcName, d.PurcNRIC, d.PurcAddress, d.PurcContactPerson, d.PurcTel, " & _
                                    "d.PurcFax, d.PurcMobile, d.PurcDisbursement, d.PurcSCompany, d.PurcSAddress, d.PurcSContactPerson, " & _
                                    "d.PurcSTel, d.PurcSFax, d.PurcSMobile, d.OtherRemarks, ISNULL(d.UpdateDate, d.CreateDate) as CreateDate, " & _
                                    "ISNULL(u.Name, c.Name) as CreateBy, d.StatusDelete FROM AW_DocTakeUpSale d " & _
                                    "LEFT JOIN AW_Staff u ON d.UpdateBy = u.StaffId LEFT JOIN AW_Staff c ON " & _
                                    "d.CreateBy = c.StaffId WHERE DocSaleId=@DocSaleId"
        objDB.AddParameter("DocSaleId", Data.SqlDbType.UniqueIdentifier, New Guid(DocId))
        objDB.FillData(TempDT, "DocTakeUpSale", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()
        Return TempDT
    End Function

    Private Function LoadAuction(ByVal DocId As String) As Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT d.DocAucTitle, d.REN, d.Lister, d.Premise, d.Price, d.AuctionDate, d.Remarks, d.ContactPerson, " & _
                                    "d.Bank, d.ContactNo, d.Commission, d.CPRemarks, d.Purchaser, d.NRIC, d.Disbursement, d.Address, " & _
                                    "d.PContactNo, ISNULL(d.UpdateDate, d.CreateDate) as CreateDate, " & _
                                    "ISNULL(u.Name, c.Name) as CreateBy, d.StatusDelete, d.DocDate, d.FaxNo FROM AW_DocTakeUpAuction d " & _
                                    "LEFT JOIN AW_Staff u ON d.UpdateBy = u.StaffId LEFT JOIN AW_Staff c ON " & _
                                    "d.CreateBy = c.StaffId WHERE DocAucId=@DocAucId"
        objDB.AddParameter("DocAucId", Data.SqlDbType.UniqueIdentifier, New Guid(DocId))
        objDB.FillData(TempDT, "DocTakeUpAuction", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()
        Return TempDT
    End Function

    Private Function LoadProposal(ByVal DocId As String) As Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT d.DocPropId, d.DocPropTitle, d.DocTo, d.ContactNo, d.Address, d.MailFax, d.REN, d.Attn, " & _
                                    "d.DocDate, d.MeetType, d.YourType, d.YourName, d.OurName, d.OnDate, ISNULL(d.UpdateDate, d.CreateDate) as CreateDate, " & _
                                    "ISNULL(u.Name, c.Name) as CreateBy, d.StatusDelete, d.ListType FROM AW_DocProposal d " & _
                                    "LEFT JOIN AW_Staff u ON d.UpdateBy = u.StaffId LEFT JOIN AW_Staff c ON " & _
                                    "d.CreateBy = c.StaffId WHERE DocPropId=@DocPropId"
        objDB.AddParameter("DocPropId", Data.SqlDbType.UniqueIdentifier, New Guid(DocId))
        objDB.FillData(TempDT, "DocProposal", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()
        Return TempDT
    End Function

    Private Function LoadExclusive(ByVal DocId As String) As Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT d.DocExTitle, d.REN, d.Lister, d.Premise, d.Price, d.Remarks, d.ContactPerson, " & _
                                    "d.ContactNo, d.Commission, d.CPRemarks, ISNULL(d.UpdateDate, d.CreateDate) as CreateDate, " & _
                                    "ISNULL(u.Name, c.Name) as CreateBy, d.StatusDelete, d.DocDate, d.FaxNo FROM AW_DocExclusive d " & _
                                    "LEFT JOIN AW_Staff u ON d.UpdateBy = u.StaffId LEFT JOIN AW_Staff c ON " & _
                                    "d.CreateBy = c.StaffId WHERE DocExId=@DocExId"
        objDB.AddParameter("DocExId", Data.SqlDbType.UniqueIdentifier, New Guid(DocId))
        objDB.FillData(TempDT, "DocExclusive", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()
        Return TempDT
    End Function

    Private Function LoadProperty(ByVal DocId As String) As Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT DocPPId, DocPropId, Address, Location, Price, Tenure, Type, LA, BU, " & _
                                    "Remarks, 'O' AS Status, '1' AS Visible FROM AW_DocProposalProperty WHERE " & _
                                    "DocPropId=@DocPropId"
        objDB.AddParameter("DocPropId", Data.SqlDbType.UniqueIdentifier, New Guid(DocId))
        objDB.FillData(TempDT, "DocProposalProperty", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()
        Return TempDT
    End Function
End Class
